home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr28 / mxmnu239.zip / METER.INC < prev    next >
Text File  |  1993-03-22  |  3KB  |  111 lines

  1. Comment
  2. ========================================
  3.  
  4.  METER.INC
  5.  
  6.  Copyright 1990-1992 Computer Tyme * All rights reserved
  7.  
  8.  This software metering module counts how many users are using an
  9.  application and limits it to a fixed number of users. Thus, you can
  10.  save money on other software by limiting the number of people who can
  11.  run an application to the number of copies you own.
  12.  
  13.  This can also be used to limit an application to 1 user where the
  14.  application only works on a network if for one user at a time.
  15.  
  16.  To use this module, add the line INCLUDE 'METER.INC' to your menu.
  17.  Then under the OnKey you want to meter:
  18.  
  19.  OnKey 'W'
  20.     |if Limit('WP',6) then Return   ;limit to 6 users
  21.     WP
  22.  
  23.  In the above example, a Word Perfect choice is limited to 6 users. Thus
  24.  you may have 20 users total but only 6 can run Word Perfect at the same
  25.  time.
  26.  
  27.  The way it works is, MarxMenu creates a semaphore when it runs an
  28.  application and stores the semaphore name in an environment variable
  29.  named METER. When the user returns to the menu the semaphore is
  30.  cleared. If the user turns off their computer in the middle of an
  31.  application, netware will clear the semaphore within 15 minutes.
  32.  
  33.  
  34.  USAGE LOGGING:
  35.  --------------
  36.  
  37.  OnKey 'W'
  38.     |LogIt('WordPerfect')
  39.     WP
  40.  
  41.  This will send a log line to the log file that is a comma delimited
  42.  ascii line with fields as follows:
  43.  
  44.  "UserName","Program","Start Time","End Time"
  45.  
  46. ========================================
  47. EndComment
  48.  
  49. var
  50.   LogFileName = 'U:MARXLOG.TXT'
  51.  
  52. MeterInit
  53. LogToFile
  54.  
  55. ;------ Metering Procedures
  56.  
  57. Procedure MeterInit
  58. var SemaName
  59.    SemaName = ReadEnv('METER')
  60.    if SemaName > '' then NovCloseSemaphore('XM-' + SemaName)
  61.    SetEnv('METER=')
  62. EndProc
  63.  
  64.  
  65. Procedure Limit (Name,Count)
  66.    if NovSemaphoreUsers('XM-' + Name) >= Count
  67.       TooManyUsers(Name)
  68.       Return True
  69.    endif
  70.    NovOpenSemaphore('XM-' + Name,0) ; 'XM-' is for XMETER compatibility
  71.    SetEnv('METER=' + Name)
  72.    Return False
  73. EndProc
  74.  
  75.  
  76. Procedure TooManyUsers(Name)
  77. var Ch
  78.    BoxHeader = ' * Press any Key * '
  79.    DrawBox 11 21 length(Name) + 30 3
  80.    UseArrows Off
  81.    Cursor Off
  82.    TextColor MenuHeaderFG MenuBG
  83.    Write Char(7) ' All copies of ' Name ' are in Use!'
  84.    Ch = ReadKey
  85.    EraseTopWindow
  86. EndProc
  87.  
  88. ;------ Usage Logging Procedures
  89.  
  90. Procedure LogIt (Name)
  91.    SetEnv('LOGIT=' + Name)
  92.    SetEnv('INTIME=' + TimeString)
  93. EndProc
  94.  
  95.  
  96. Procedure LogToFile
  97. var Program St
  98.    Program = ReadEnv('LOGIT')
  99.    if Program = '' then Return
  100.  
  101.    St = '"' + NovLoginName + '","' + Program + '","'
  102.    St = St + ReadEnv('INTIME') + '","'+ TimeString(Now) + '"'
  103.    FileLog(LogFileName,St)
  104.  
  105.    ;--- Clear Environment Variables
  106.  
  107.    SetEnv('LOGIT=')
  108.    SetEnv('INTIME=')
  109. EndProc
  110.  
  111.